<template>
	<view class="mainpadding2">
		<view class="flexbetween margin_top mainpadding_top radius" style="background-color: #1ba95b;">
			<view class="titletext sanshier fonweight" style="color: #ffffff;">星期一</view>
			<u-icon name="plus-circle-fill" color="#ffffff" size="28" @click="addkc(1)"></u-icon>
		</view>
		<view class="flexleft flex_wrap">
			<view class="huibox flexleft" v-for="item in dataAll.week_1" :key="item.id" @click="edititem(item)">
				<text class="xiaolv fonweight" v-if="item.status==2">锁</text>
				<text
					class="margin_right2">{{item.price}}元/{{item.cgtime.start_time}}-{{item.cgtime.end_time}}</text>
				<u-icon name="edit-pen-fill" color="#1ba95b" size="18"></u-icon>
			</view>
		</view>
		<view class="flexbetween margin_top mainpadding_top radius" style="background-color: #1ba95b;">
			<view class="titletext sanshier fonweight" style="color: #ffffff;">星期二</view>
			<u-icon name="plus-circle-fill" color="#ffffff" size="28" @click="addkc(2)"></u-icon>
		</view>
		<view class="flexleft flex_wrap">
			<view class="huibox flexleft" v-for="item in dataAll.week_2" :key="item.id" @click="edititem(item)">
				<text class="xiaolv fonweight" v-if="item.status==2">锁</text>
				<text
					class="margin_right2">{{item.price}}元/{{item.cgtime.start_time}}-{{item.cgtime.end_time}}</text>
				<u-icon name="edit-pen-fill" color="#1ba95b" size="18"></u-icon>
			</view>
		</view>
		<view class="flexbetween margin_top mainpadding_top radius" style="background-color: #1ba95b;">
			<view class="titletext sanshier fonweight" style="color: #ffffff;">星期三</view>
			<u-icon name="plus-circle-fill" color="#ffffff" size="28" @click="addkc(3)"></u-icon>
		</view>
		<view class="flexleft flex_wrap">
			<view class="huibox flexleft" v-for="item in dataAll.week_3" :key="item.id" @click="edititem(item)">
				<text class="xiaolv fonweight" v-if="item.status==2">锁</text>
				<text
					class="margin_right2">{{item.price}}元/{{item.cgtime.start_time}}-{{item.cgtime.end_time}}</text>
				<u-icon name="edit-pen-fill" color="#1ba95b" size="18"></u-icon>
			</view>
		</view>
		<view class="flexbetween margin_top mainpadding_top radius" style="background-color: #1ba95b;">
			<view class="titletext sanshier fonweight" style="color: #ffffff;">星期四</view>
			<u-icon name="plus-circle-fill" color="#ffffff" size="28" @click="addkc(4)"></u-icon>
		</view>
		<view class="flexleft flex_wrap">
			<view class="huibox flexleft" v-for="item in dataAll.week_4" :key="item.id" @click="edititem(item)">
				<text class="xiaolv fonweight" v-if="item.status==2">锁</text>
				<text
					class="margin_right2">{{item.price}}元/{{item.cgtime.start_time}}-{{item.cgtime.end_time}}</text>
				<u-icon name="edit-pen-fill" color="#1ba95b" size="18"></u-icon>
			</view>
		</view>
		<view class="flexbetween margin_top mainpadding_top radius" style="background-color: #1ba95b;">
			<view class="titletext sanshier fonweight" style="color: #ffffff;">星期五</view>
			<u-icon name="plus-circle-fill" color="#ffffff" size="28" @click="addkc(5)"></u-icon>
		</view>
		<view class="flexleft flex_wrap">
			<view class="huibox flexleft" v-for="item in dataAll.week_5" :key="item.id" @click="edititem(item)" >
				<text class="xiaolv fonweight" v-if="item.status==2">锁</text>
				<text
					class="margin_right2">{{item.price}}元/{{item.cgtime.start_time}}-{{item.cgtime.end_time}}</text>
				<u-icon name="edit-pen-fill" color="#1ba95b" size="18"></u-icon>
			</view>
		</view>
		<view class="flexbetween margin_top mainpadding_top radius" style="background-color: #1ba95b;">
			<view class="titletext sanshier fonweight" style="color: #ffffff;">星期六</view>
			<u-icon name="plus-circle-fill" color="#ffffff" size="28" @click="addkc(6)"></u-icon>
		</view>
		<view class="flexleft flex_wrap">
			<view class="huibox flexleft" v-for="item in dataAll.week_6" :key="item.id" @click="edititem(item)">
				<text class="xiaolv fonweight" v-if="item.status==2">锁</text>
				<text
					class="margin_right2">{{item.price}}元/{{item.cgtime.start_time}}-{{item.cgtime.end_time}}</text>
				<u-icon name="edit-pen-fill" color="#1ba95b" size="18"></u-icon>
			</view>
		</view>
		<view class="flexbetween margin_top mainpadding_top radius" style="background-color: #1ba95b;">
			<view class="titletext sanshier fonweight" style="color: #ffffff;">星期日</view>
			<u-icon name="plus-circle-fill" color="#ffffff" size="28" @click="addkc(0)"></u-icon>
		</view>
		<view class="flexleft flex_wrap">
			<view class="huibox flexleft" v-for="item in dataAll.week_0" :key="item.id" @click="edititem(item)">
				<text class="xiaolv fonweight" v-if="item.status==2">锁</text>
				<text
					class="margin_right2">{{item.price}}元/{{item.cgtime.start_time}}-{{item.cgtime.end_time}}</text>
				<u-icon name="edit-pen-fill" color="#1ba95b" size="18"></u-icon>
			</view>
		</view>
		<u-modal :show="show" title="时间表" confirmText="确认" @confirm="chongzhi" cancelText="取消"
			@cancel="chongzhicancel" showCancelButton>
			<view class="slot-content" style="width: 600rpx;">
				<!-- <view class="flexbetween margin_top" @click="timetype=1;messageTime.timeShow=true;">
					<view class="main_size bold hei_text">开始时间：</view>
					<view class="flexright">
						<input type="text" class="textright" placeholder="请选择" disabled
							v-model="start_time">
						<u-icon name="arrow-right" color="#999" size="16"></u-icon>
					</view>
				</view>
				<view class="flexbetween margin_top" @click="timetype=2;messageTime.timeShow=true;">
					<view class="main_size bold hei_text">结束时间：</view>
					<view class="flexright">
						<input type="text" class="textright" placeholder="请选择" disabled
							v-model="end_time">
						<u-icon name="arrow-right" color="#999" size="16"></u-icon>
					</view>
				</view> -->
				<view class="flexbetween margin_top" @click="jumpurl('/pages_mypage/changdishijianb?type=1')">
					<view class="main_size bold hei_text" style="min-width: 200rpx;">选择时间段：</view>
					<view class="flexright">
						<input type="text" class="textright" placeholder="请选择" disabled
							v-model="timetext">
						<u-icon name="arrow-right" color="#999" size="16"></u-icon>
					</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="main_size bold hei_text">价格：</view>
					<input type="digit" class="textright" placeholder="请输入"
						v-model="price">
				</view>
				<view class="flexbetween margin_top" @click="timetype=3;messageTime.timeShow=true;">
					<view class="main_size bold hei_text" style="min-width: 220rpx;">锁场结束时间：</view>
					<view class="flexright">
						<input type="text" class="textright" placeholder="请选择" disabled
							v-model="locktime">
						<u-icon name="arrow-right" color="#999" size="16"></u-icon>
					</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="main_size bold hei_text">状态：</view>
					<view class="flexright">
						<u-radio-group v-model="status" placement="row" circle>
							<u-radio activeColor="#1ba95b" label="正常" :customStyle="{marginRight: '30rpx'}"
								:name="1"></u-radio>
							<u-radio activeColor="#1ba95b" label="锁场" :name="2"></u-radio>
						</u-radio-group>
					</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="main_size bold hei_text">锁场用户名：</view>
					<input type="text" class="textright" placeholder="请输入" v-model="username">
				</view>
				<view class="flexbetween margin_top">
					<view class="main_size bold hei_text">锁场手机号：</view>
					<input type="number" class="textright" placeholder="请输入" v-model="usermobile">
				</view>
				<view class="bigbtn margin_top6" v-if="listid" @click="delitem">删除</view>
			</view>
		</u-modal>
		<timePicker :messageTime="messageTime" @timeConfirm="timeConfirm"></timePicker>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				dataAll: {},
				week_num: 0, //星期:0=星期日,1=星期一,2=星期二,3=星期三,4=星期四,5=星期五,6=星期六
				cg_id: "",
				price:"",
				start_time: "",
				end_time: "",
				show: false,
				listid: "",
				type: 1, //身份:1=主办方,2=俱乐部,3=团队，4场馆，5教练
				cgShow: false,
				cgList: [],
				jlShow: false,
				jlList: [],
				messageTime:{
					timeShow:false,
					title:"选择时间",
					mode:"date",//date日期，datetime年月日时分秒，time时间
				},
				timetype:1,
				cg_time_id:"",
				timetext:"",
				user_zbfapply_listid:"",
				locktime:"",
				status:1,
				username:"",
				usermobile:"",
			}
		},
		onLoad(options) {
			this.user_zbfapply_listid=options.user_zbfapply_listid
			uni.$on("checktime",data=>{
				console.log(data,"惊雷");
				this.timetext = data.start_time+"-"+data.end_time
				this.cg_time_id = data.id
			})
			this.cg_id = options.id
			this.getDetail()
			this.userinfomsg()
		},
		onUnload() {
			uni.$off("checktime")
		},
		methods: {
			jumpurl(url) {
				uni.navigateTo({
					url:url+'&user_zbfapply_listid='+this.user_zbfapply_listid
				})
			},
			edititem(item){
				this.week_num = item.week_num
				this.timetext = item.cgtime.start_time+"-"+item.cgtime.end_time
				this.locktime = item.locktime_text
				this.status = Number(item.status)
				this.username = item.username
				this.usermobile = item.usermobile
				this.cg_time_id = item.cg_time_id
				this.price = item.price
				this.listid = item.id
				this.show = true
			},
			timeConfirm(e){
				if(this.timetype==1){
					this.start_time = e
				}else if(this.timetype==2){
					this.end_time = e
				}else{
					this.locktime = e
				}
			},
			delitem(){
				httpRequest.request('/api/cgcl/deleteCgCgb', 'GET', {
					id:this.listid,
					user_zbfapply_id:this.user_zbfapply_listid
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						this.chongzhicancel()
						this.getDetail()
					}
				})
			},
			userinfomsg() {
				httpRequest.request('/api/user/index', 'GET', {}).then(res => {
					this.type = res.data.userzbfapply.type
					this.pageShow = true
				})
			},
			chongzhicancel() {
				this.timetext = ""
				this.cg_time_id = ""
				this.locktime = ""
				this.status = 1
				this.username = ""
				this.usermobile = ""
				this.price = ""
				this.listid = ""
				this.show = false
			},
			chongzhi() {
				if(this.cg_time_id==""){
					httpRequest.toast("请选择时间段")
					return false
				}
				if(this.price==""){
					httpRequest.toast("请输入价格")
					return false
				}
				if(this.locktime==""){
					httpRequest.toast("请选择锁场结束时间")
					return false
				}
				if(this.username==""){
					httpRequest.toast("请输入用户名")
					return false
				}
				if(this.usermobile==""){
					httpRequest.toast("请输入手机号")
					return false
				}
				let url = "/api/cgcl/addCgKcb"
				let data = {
					cg_id:this.cg_id,
					week_num:this.week_num,
					cg_time_id:this.cg_time_id,
					price:this.price,
					user_zbfapply_id:this.user_zbfapply_listid,
					locktime:this.locktime,
					status:this.status,
					username:this.username,
					usermobile:this.usermobile,
				}
				if (this.listid) {
					this.$set(data, "id", this.listid)
					url = "/api/cgcl/editCgCgb"
				}
				httpRequest.request(url, 'GET', data).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						this.chongzhicancel()
						this.getDetail()
					}
				})
			},
			addkc(val) {
				this.week_num = val
				this.show = true
			},
			getDetail() {
				httpRequest.request("/api/cgcl/getCgCgbIndex", 'GET', {
					cg_id: this.cg_id,
					user_zbfapply_id:this.user_zbfapply_listid
				}).then(res => {
					this.dataAll = res.data
				})
			}
		}
	}
</script>

<style>
	.huibox {
		padding: 10rpx 20rpx;
		border-radius: 50rpx;
		color: #999;
		margin: 30rpx 30rpx 0 0;
		background-color: #f7f7f7;
		font-size: 26rpx;
	}
</style>